//
//  MatchPageCell.swift
//  JTYP
//
//  Created by Groot on 2017/12/9.
//  Copyright © 2017年 inspur. All rights reserved.
//

class MatchPageCell: UICollectionViewCell {
    
    static let CellIdentifier = String(describing: MatchPageCell.self)

    @IBOutlet weak var iconVIew: UIImageView!
    @IBOutlet weak var titleLab: UILabel!
    @IBOutlet weak var progressView: UIProgressView!
    
    @IBOutlet weak var pTimeLab: UILabel!
    @IBOutlet weak var planLab: UILabel!
    @IBOutlet weak var joinLab: UILabel!
    
    @IBOutlet weak var dividingLine: UIView!
    
    override func awakeFromNib() {
        progressView.progressViewStyle = .default
        progressView.trackTintColor = UIColorFromRGB(rgbValue: 0xEEEEEE)
        progressView.progressTintColor = DefaultColor.green
        
        bringSubview(toFront: dividingLine)
    }
    
    func setData(obj: Match?) {
        titleLab.text = obj?.name
        iconVIew.image = UIImage.init(named: obj?.type == 2 ? "match_sai" : "match_yue")
        
        pTimeLab.text = String.init(describing: obj?.starttime?.prefix(10) ?? "") //obj?.starttime//
        planLab.text = "\(obj?.plannedenrollment ?? 0)"
        joinLab.text = "\(obj?.actualenrollment ?? 0)"
        
        let planNum = Float(obj?.plannedenrollment ?? 0)
        let actNum = Float(obj?.actualenrollment ?? 0)
        
        // 包名进度
        var progress: Float = 0
        if planNum == 0 {
            progress = 0
        }else {
            progress = actNum / planNum
        }
        
        progressView.setProgress(Float.minimum(1, progress), animated: true)
    }
    
}
